  // const SURL = "http://rest.izzht.cn/"; // 接口
 //const SURL =  "http://192.168.3.155:8084/";//涛哥ip
  const SURL =  "http://192.168.3.145:80/";//崔谊
  //const SURL =  "http://192.168.3.52:8000/";//彭阳
 // const SURL =  "http://192.168.1.162:8000/";//彭阳
  const imgUrl = "http://zzhtwl.oss-cn-qingdao.aliyuncs.com/"; // 图片地址
 var  validateImgSrc=SURL+"api/site/code";

 //验证图形验证码并发送短信(ZJF)
  //TODO！未完成
 function checkImgCode(params) {
     Vue.http.post(SURL+'site/checkImgeCode',params,{emulateJSON:true}).then(function (res) {
         console.log(res)
     })
 }
 
//点击图形验证码刷新
function clickCode(d) {
    validateImgSrc=SURL+"api/site/code?id="+Math.random();
    d.children[0].src=validateImgSrc
}
//发送短信验证吗
function sendMessage(d,params) {
    var reg = /^1[0-9]{10}$/,n=60;//手机号正则
    flag = reg.test(params.userPhone); //true
    //type:1未注册 2，已经注册
    if(flag)
        Vue.http.post(SURL+"app/site/getMessageCode",params,{emulateJSON : true}).then(function(res){
           // console.log(res)
            if(res.body.status==1){
            //   _this.messageStatus=res.body.status;
               //alert('发送成功');
                showDefault('success','发送成功');

                //点击按钮倒计时60s		   pointer-events: none;
                d.className+=' '+' disabled';
                //增加class

                var timer=setInterval(function(){
                    n--;
                    n=n>10?n:'0'+n

                   d.innerText='0 : '+n;
                    if(n<=0){
                        //删除class
                        d.className = d.className.replace('disabled', ' ');
                        d.innerText='获取验证码'
                        clearInterval(timer)

                    }

                },1000)

            }else{
                showDefault('fail','发送失败');
            }

        }).catch(function(res){
            console.log(res)
        });
    else
        alert('请填写正确的手机号')
}
//验证短信验证码

  function checkMessage(params){


         Vue.http.post(SURL+'app/site/checkMessage',params,{emulateJSON : true}).then(function(res){
           // console.log(res)
              if(res.body.status=='1'){
                  alert(res.body.msg)
              }

          })
  }
  apiready = function(){
      api.parseTapmode();
  }

  function showDefault(type,font){
      var toast = new auiToast({
      })
      font=font||'';
      switch (type) {

          case "success":
              toast.success({
                  title:font,
                  duration:2000
              });
              break;
          case "fail":
              toast.fail({
                  title:font,
                  duration:2000
              });
              break;
          case "custom":
              toast.custom({
                  title:"提交成功",
                  html:'<i class="aui-iconfont aui-icon-laud"></i>',
                  duration:2000
              });
              break;
          case "loading":
              toast.loading({
                  title:"加载中",
                  duration:2000
              },function(ret){
                  console.log(ret);
                  // setTimeout(function(){
                  //     toast.hide();
                  // }, 3000)
              });
              break;
          case 'hide':{
              toast.hide();
          }
          default:
              // statements_def
              break;
      }
  }

  //获取url参数

  /*获取url参数*/
  function getUrlParam(name, str) {
      var url;
      if (str) {
          url = str.split("?")[1];
      } else {
          url = window.location.search.replace("?", "");
      }
      url = url.split("&");
      var ret = {};
      url.forEach(function (o, i) {
         // console.log(o)
          var d = o.split("=");
          ret[d[0]] = decodeURI(d[1]);
      });
      if (name)
          return ret[name];
      else
          return ret;
  }

  //价钱后面加 .00
  function splitPrice(num) {
      if(parseFloat(num).toString().indexOf('.')==-1){
          num=num+'.00'
      }else{
          num =num;
      }
      return num.toString().split('.')
  }
//点击后退
  window.onload=function(){
      if(document.querySelector('.aui-icon-left'))
      document.querySelector('.aui-icon-left').addEventListener('click',function () {
          history.go(-1)
      })

  };
  //判断后台返回数据是否有http
  function orImg(src){
      if(src){
          if(src.indexOf('http')==-1){
              src=imgUrl+src
          }else{
              src=src
          }

      }

      return  src
  }
  var token ='32253e9ba7de4a68b18c51aed7c1b3' ;//window.localStorage.getItem("token");
function setToken(){
    Vue.http.interceptors.push(function(request, next) {
        request.headers.set('token', token); //setting request.headers
        // const layer = top.layer.load(); //show loading....
        showDefault('loading','');//后期用layer
        next(function(response){
            showDefault('hide','');
            if(response.body.status!=1){
                showDefault('fail',response.body.msg)
            }
            // top.layer.close(layer); //get data after hide loading....
            if(response.body.code===401){ //与后台约定登录失效的返回码
                parent.location.href ='/login.html';
            }
            return response
        })
    })
}
  // Vue.http.interceptors.push((request, next) => {
  //     //request.headers.set('token', token); //setting request.headers
  //     const layer = top.layer.load(); //show loading....
  //     next((response) => {
  //         top.layer.close(layer); //get data after hide loading....
  //         return response
  //     })
  // })
//保留两位小数
  function returnFloat(value) { //保留俩位小数
      var value = Math.round(parseFloat(value) * 100) / 100;
      var xsd = value.toString().split(".");
      if(xsd.length == 1) {
          value = value.toString() + ".00";
          return value;
      }
      if(xsd.length > 1) {
          if(xsd[1].length < 2) {
              value = value.toString() + "0";
          }
          return value;
      }
  }

//返回刷新
  function xyyReload() {
      if(window.name!="hasLoad"){
          location.reload();
          window.name = "hasLoad";
      }else{
          window.name="";
      }
  }

  //数组去重
  Array.prototype.distinct = function (){
      var arr = this,
          i,
          obj = {},
          result = [],
          len = arr.length;
      for(i = 0; i< arr.length; i++){
          if(!obj[arr[i]]){ //如果能查找到，证明数组元素重复了
              obj[arr[i]] = 1;
              result.push(arr[i]);
          }
      }
      return result;
  };
/* Vue.http.interceptors.push({
  request(request) {
    const jwtToken = JSON.parse(localStorage.getItem('auth.jwt_token'));
    if (jwtToken) {
      Vue.http.headers.common.Authorization = `Bearer ${jwtToken.access_token}`;
    } else {
      delete Vue.http.headers.common.Authorization;
    }
    return request;
  },
  response(response) {
    if (response.status === 400 || response.status === 401) {
      // 当 Token 已经失效时，清空所有保存在 localStorage 的数据
      localStorage.clear();
    }
    return response;
  },
});*/



